#include <bits/stdc++.h>
#include <type_traits>
using namespace std;

class Solution {
public:
    int totalFruit(vector<int>& fruits) {
        int hash[100001]={0};
        int n = fruits.size();
        int left=0; int right = 0; int kind=0;
        int ans = 0;
        while(right < n){
            ++hash[fruits[right]];
            if(hash[fruits[right]]==1) ++kind;
            ++right;
            while(kind>2){
                --hash[fruits[left]];
                if(hash[fruits[left]]==0) --kind;
                ++left;
            }
            ans = max(ans, right-left);
        }
        return ans;
    }
};

int main(){
    Solution solution;
    vector<int> nums = {0,1,2,2};
    solution.totalFruit(nums);
}